﻿module Sustainalytics.ProductInvolvement.Security {

    import Routing = Sustainalytics.Routing;

    export class PICompanyRouteSecurityService implements Routing.IRouteSecurityService {

        constructor(
            private $q: ng.IQService,
            private PIPermissionsService: PIPermissionsService) {
        }

        validate(security: Routing.RouteSecurity): ng.IPromise<boolean> {
            var ctx = this;

            var valid = ctx.PIPermissionsService.hasCompanyPI();

            return ctx.$q.when(valid);
        }
    }


    export var piCompanyRouteSecurityServiceName = 'PICompanyRouteSecurityService';

    angular.module(piSecurityModuleName).service(piCompanyRouteSecurityServiceName, PICompanyRouteSecurityService);


    export class PIMultiCompanyRouteSecurityService implements Routing.IRouteSecurityService {

        constructor(
            private $q: ng.IQService,
            private PIPermissionsService: PIPermissionsService) {
        }

        validate(security: Routing.RouteSecurity): ng.IPromise<boolean> {
            var ctx = this;

            var valid = ctx.PIPermissionsService.hasMultiCompanyPI();

            return ctx.$q.when(valid);
        }
    }

    export var piMultiCompanyRouteSecurityServiceName = 'PIMultiCompanyRouteSecurityService';

    angular.module(piSecurityModuleName).service(piMultiCompanyRouteSecurityServiceName, PIMultiCompanyRouteSecurityService);
}